package alg45;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;

public class CheckWork {
    public static ArrayList<Integer> readfile(String filepath) throws FileNotFoundException, IOException {
        ArrayList<Integer> unFinishedList = new ArrayList<Integer>();
        try {

            File file = new File(filepath);
            if (!file.isDirectory()) {
                System.out.println("文件");
                System.out.println("path=" + file.getPath());
                System.out.println("absolutepath=" + file.getAbsolutePath());
                System.out.println("name=" + file.getName());

            } else if (file.isDirectory()) {
                String[] filelist = file.list();
                for (int i = 0; i < filelist.length; i++) {
                    File readfile = new File(filepath + "/" + filelist[i]);
                    if (!readfile.isDirectory()) {
                        Long initFileSize = 255l;
                        Long initFileSize2 = 256l;
                        Long realFileSize = readfile.length();
                        if (initFileSize.longValue() == realFileSize.longValue()||initFileSize2.longValue() == realFileSize.longValue() ) {
                            unFinishedList.add(getIdFromFile(readfile.getName()));
                        }


                    } else if (readfile.isDirectory()) {
                        readfile(filepath + "\\" + filelist[i]);
                    }
                }

            }
            return unFinishedList;
        } catch (FileNotFoundException e) {
            System.out.println("readfile()   Exception:" + e.getMessage());
        }
        return null;
    }

    private static Integer getIdFromFile(String name) {
        String[] split = name.split("_");
        String[] split1 = split[2].split("\\.");
        return new Integer(split1[0]);
    }



    private static void printUnFinishedList(ArrayList<Integer> unFinishedList) {
        System.out.println("有" + unFinishedList.size() + "人的作业未完成 ，或者提交有问题");
        System.out.println("学号如下:");

        int count = 1;
        for (Integer item : unFinishedList) {
            System.out.print(item + " ");
            if (count++ % 10 == 0) {
                System.out.println();
            }
        }
    }

    public static void main(String[] args) {
        try {
            String path="";
            ArrayList<Integer> unFinishedList = CheckWork.readfile(path);
            unFinishedList.sort(Comparator.naturalOrder());
            printUnFinishedList(unFinishedList);

        } catch (Exception ex) {

        }

    }
}
